#ifndef ZT_PM518_IOCTL_H
#define ZT_PM518_IOCTL_H

#define GET_ULONG_BITS(dataDoubleWord,dataDoubleMask,nBit) (((dataDoubleWord) >> (nBit)) & (dataDoubleMask))
#define SET_ULONG_BITS(dataDoubleWord,dataDoubleMask,nBit,nState) (((dataDoubleWord)  & (~((dataDoubleMask) << (nBit)))) | (((nState) & (dataDoubleMask)) << (nBit)))

#define PM518_IOCOUTLSIZE               sizeof(unsigned long) * 2
#define PM518_IOCINLSIZE                sizeof(unsigned long) * 1
#define PM518_IOCADSFIFOCANREADNUMSIZE  sizeof(unsigned long) * 1
#define PM518_IOCADSTOPSIZE             sizeof(unsigned long) * 0
#define PM518_IOCGETCTRLWORDSIZE        sizeof(unsigned long) * 1
#define PM518_IOCSETCTRLWORDSIZE        sizeof(unsigned long) * 1
#define PM518_IOCENABLEIRQSIZE          sizeof(unsigned long) * 1
#define PM518_IOCDISABLEIRQSIZE         sizeof(unsigned long) * 0
#define PM518_IOCFIFORESIZESIZE         sizeof(unsigned long) * 1
#define PM518_IOCREADMEMSIZE            sizeof(unsigned long) * 1
#define PM518_IOCWRITEMEMSIZE           sizeof(unsigned long) * 2
#define PM518_IOCDASFIFOCANREADNUMSIZE  sizeof(unsigned long) * 1
#define PM518_IOCDAFIFOCLEARSIZE        sizeof(unsigned long) * 0
/*
* Ioctl definitions
*/

/* Use 255 as magic number */
#define PM518_IOC_MAGIC  255
/* Please use a different 8-bit number in your code */

#define PM518_IOC_OUTW           _IOC( _IOC_WRITE            , PM518_IOC_MAGIC, 0, PM518_IOCOUTLSIZE )
#define PM518_IOC_INW            _IOC( _IOC_WRITE | _IOC_READ, PM518_IOC_MAGIC, 1, PM518_IOCINLSIZE )

//parameter: 0:SFifo can read number
//number of parameter: 1
#define PM518_IOC_ADSFIFOCANREADNUM        _IOC( _IOC_READ , PM518_IOC_MAGIC, 3, PM518_IOCADSFIFOCANREADNUMSIZE )
//parameter: 
//number of parameter: 0
#define PM518_IOC_ADSTOP                   _IOC( _IOC_NONE , PM518_IOC_MAGIC, 4, PM518_IOCADSTOPSIZE )

#define PM518_IOC_GETCTRLWORD              _IOC( _IOC_READ , PM518_IOC_MAGIC, 5, PM518_IOCGETCTRLWORDSIZE )
#define PM518_IOC_SETCTRLWORD              _IOC( _IOC_READ , PM518_IOC_MAGIC, 6, PM518_IOCSETCTRLWORDSIZE )

#define PM518_IOC_OUTB         _IOC( _IOC_WRITE            , PM518_IOC_MAGIC, 7, PM518_IOCOUTLSIZE )
#define PM518_IOC_INB          _IOC( _IOC_WRITE | _IOC_READ, PM518_IOC_MAGIC, 8, PM518_IOCINLSIZE )

#define PM518_IOC_ENABLEIRQ    _IOC( _IOC_WRITE | _IOC_READ, PM518_IOC_MAGIC, 9, PM518_IOCINLSIZE )
#define PM518_IOC_DISABLEIRQ   _IOC( _IOC_WRITE | _IOC_READ, PM518_IOC_MAGIC, 10, PM518_IOCINLSIZE )
#define PM518_IOC_FIFO_RESIZE  _IOC( _IOC_WRITE | _IOC_READ, PM518_IOC_MAGIC, 11, PM518_IOCFIFORESIZESIZE )
#define PM518_IOC_READ_MEM		_IOC( _IOC_WRITE | _IOC_READ, PM518_IOC_MAGIC, 12, PM518_IOCREADMEMSIZE )
#define PM518_IOC_WRITE_MEM 	_IOC( _IOC_WRITE | _IOC_READ, PM518_IOC_MAGIC, 13, PM518_IOCWRITEMEMSIZE )

//ZCD 13-10-15
#define PM518_IOC_GETERRORCODE             _IOC( _IOC_READ , PM518_IOC_MAGIC, 14, sizeof(long) )

#define PM518_IOC_DASFIFOCANREADNUM        _IOC( _IOC_READ , PM518_IOC_MAGIC, 15, PM518_IOCDASFIFOCANREADNUMSIZE )
#define PM518_IOC_DAFIFOCLEAR              _IOC( _IOC_NONE , PM518_IOC_MAGIC, 16, PM518_IOCDAFIFOCLEARSIZE )

#define PM518_IOC_MAXNR 16

#endif
